package com.szp.drug.config;

import com.szp.drug.entity.DrugAdmin;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.List;

/**
 * SecurityAdmin实体类 去实现SpringSecurity中的User类
 * 来封装原始的DrugAdmin对象及它拥有的角色及权限
 * @author SuZePing
 * @create 2021-02-22 10:39
 * @E-mail suzeping10@126.com
 */
public class SecurityAdmin extends User {

	private DrugAdmin originalAdmin;

	/**
	 * 构造器
	 * @param originalAdmin
	 * @param authorities
	 */
	public SecurityAdmin(DrugAdmin originalAdmin, List<GrantedAuthority> authorities) {
		// 调用User的构造器
		super(originalAdmin.getAccount(), originalAdmin.getPassword(), authorities);
		this.originalAdmin = originalAdmin;
		// 需要将原始的DrugAdmin中密码擦除
		this.originalAdmin.setPassword(null);
	}

	public DrugAdmin getOriginalAdmin() {
		return originalAdmin;
	}
}
